package com.cn.redis.client.impl;

import com.cn.redis.client.BackClient;
import com.cn.redis.exception.RedisConnectException;
import org.springframework.data.redis.core.RedisTemplate;

public class RedisBackTemplateImpl  implements BackClient {
    private RedisTemplate<String, Object> redisTemplate;

    public RedisBackTemplateImpl() {
    }

    public RedisBackTemplateImpl(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public void set(String seqName, long max) {
        try {
            this.redisTemplate.opsForValue().set(seqName, max);
        } catch (Exception var5) {
            var5.printStackTrace();
            throw new RedisConnectException("备用redis连接失败");
        }
    }

    public long get(String seqName) {
        Object max = 0L;
        try {
            max = this.redisTemplate.opsForValue().get(seqName);
            if (max == null) {
                max = 0L;
            }
        } catch (Exception var4) {
            var4.printStackTrace();
            throw new RedisConnectException("备用redis连接失败");
        }

        return (Long)max;
    }

    public void init() {
    }

    public RedisTemplate<String, Object> getRedisTemplate() {
        return this.redisTemplate;
    }

    public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
}